#!/bin/bash
rm -rf /home/admin/observer[1-4]
rm -rf {{ mount_point }}/data/*
rm -rf {{ mount_point }}/redo/*
kill -9 `pidof observer`
echo "start Install"
cp -ra /home/admin/oceanbase /home/admin/observer1



mkdir -p /home/admin/observer1/run && chown -R admin:admin /home/admin/observer1
mkdir -p {{ mount_point }}/data/1/obdemo/{etc3,sort_dir,sstable}
mkdir -p {{ mount_point }}/redo/log1/obdemo/{clog,etc2,ilog,slog,oob_clog}
mkdir -p /home/admin/observer1/store/obdemo
for t in {etc3,sort_dir,sstable};do ln -s {{ mount_point }}/data/1/obdemo/$t /home/admin/observer1/store/obdemo/$t; done
for t in {clog,etc2,ilog,slog,oob_clog};do ln -s {{ mount_point }}/redo/log1/obdemo/$t /home/admin/observer1/store/obdemo/$t; done
cd /home/admin/observer1 && /home/admin/observer1/bin/observer -I {{ sto_ip }} -P 21882 -p 21881 -z zone1 -d /home/admin/observer1/store/obdemo -r '{{ sto_ip }}:21882:21881' -c 10001 -n obdemo -o "__min_full_resource_pool_memory=1073741824,memory_limit=50G,system_memory=15G,datafile_size=100G,log_disk_size=100G,config_additional_dir={{ mount_point }}/data/1/obdemo/etc3;{{ mount_point }}/redo/log1/obdemo/etc2"


sleep 100
echo "start Init cluster"
obclient -h127.1 -uroot -P21881 -c -A -e "SET SESSION ob_query_timeout=1000000000;ALTER SYSTEM BOOTSTRAP ZONE 'zone1' SERVER '{{ sto_ip }}:21882';select * from oceanbase.__all_server;"
obclient -h127.1 -uroot -P21881 -c -A -e "SET GLOBAL ob_query_timeout=3600000000;SET GLOBAL ob_trx_timeout=3600000000;"

obclient -h127.1 -uroot -P21881 -c -A -e "CREATE RESOURCE UNIT test_unit_config MEMORY_SIZE = '10G',MAX_CPU = 12, MIN_CPU = 12,LOG_DISK_SIZE = '10G';CREATE RESOURCE POOL test_pool unit = 'test_unit_config', unit_num = 1, zone_list=('zone1');CREATE TENANT test resource_pool_list=('test_pool'), primary_zone=RANDOM set variables ob_compatibility_mode='mysql', ob_tcp_invited_nodes='%';"


#obclient -h127.1 -uroot@test -P2881 -c -A -e "SET GLOBAL ob_query_timeout=3600000000;SET GLOBAL ob_trx_timeout=360000000;"